//
//  TTNewStyleViewCell.swift
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/23.
//  Copyright © 2016年 陶路路. All rights reserved.
//

import UIKit

class TTNewStyleViewCell: UICollectionViewCell {
    
    var index:Int?{
        
        didSet{
            
            imageView.image = UIImage(named: "new_feature_\(index! + 1)")
            
            if index == 3{
                
                button.hidden = false
                
                starAnimation()
                
            }else{
                
                button.hidden = true
            }
        }
    }
    
    
    func starAnimation(){
        
        button.transform = CGAffineTransformMakeScale(0, 0)
        
       UIView.animateWithDuration(1, delay: 0.5, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options:[], animations: { () -> Void in
        self.button.transform = CGAffineTransformIdentity
        }) { (_) -> Void in
            
        }
    }
    
    func didClickButton(){
        
        if TTOAutoModel.sharedOautoModel.isLogin{
            
            NSNotificationCenter.defaultCenter().postNotificationName("TTWecomeController", object: nil)
            
        }else{
            
             NSNotificationCenter.defaultCenter().postNotificationName("TTWecomeController", object: self)
        }
    
    }
    
    lazy var imageView:UIImageView = {
     
        let image = UIImageView()
        
        return image
        
    }()
    
    lazy var button:UIButton = {
       let bnt = UIButton()
        bnt.setTitle("欢迎光临", forState: UIControlState.Normal)
        bnt.backgroundColor = UIColor.orangeColor()
        bnt.layer.cornerRadius = 10
        bnt.addTarget(self, action: "didClickButton", forControlEvents: UIControlEvents.TouchUpInside)
        return bnt
    }()
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        addSubview(imageView)
        addSubview(button)
        setUpUI()

    }
    
    func setUpUI(){
        
        imageView.snp_makeConstraints { (make) -> Void in
            
            make.edges.equalTo(self).offset(UIEdgeInsetsZero)
        }
        
        button.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self)
            make.width.equalTo(100)
            make.height.equalTo(36)
            make.bottom.equalTo(self).offset(-100)
        }
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
